package consys.social.core.bo;

import java.util.ArrayList;
import java.util.List;

/**
 * WallPost extends Post
 *
 * is the basic "tile" of Wall
 * It contains type which says what is stored in the post
 * discussion, likes and counts of them
 * Counts are stored separately because sometimes we don't need all discussion posts
 * but want to display number of them on the wall
 *
 * @author Petr Kunc
 */
public class WallPost extends Post implements Comparable<WallPost> {

    private static final long serialVersionUID = 1728101426785246412L;
    private WallPostType type;
    private List<DiscussionPost> discussion = new ArrayList<DiscussionPost>();
    private long discussionCount;
    private List<Entity> likes;
    private long likesCount;

    public List<DiscussionPost> getDiscussion() {
        return discussion;
    }

    public void setDiscussion(List<DiscussionPost> discussion) {
        this.discussion = discussion;
    }

    public void addDiscussionPost(DiscussionPost discussionPost) {
        this.discussion.add(discussionPost);
    }

    public void deleteDiscussionPost(DiscussionPost discussionPost) {
        this.discussion.remove(discussionPost);
    }

    public WallPostType getType() {
        return type;
    }

    public void setType(WallPostType type) {
        this.type = type;
    }

    public long getLikesCount() {
        return likesCount;
    }

    public void setLikesCount(long likesCount) {
        this.likesCount = likesCount;
    }

    public List<Entity> getLikes() {
        return likes;
    }

    public void setLikes(List<Entity> likes) {
        this.likes = likes;
    }

    public long getDiscussionCount() {
        return discussionCount;
    }

    public void setDiscussionCount(long discussionCount) {
        this.discussionCount = discussionCount;
    }

    @Override
    public int compareTo(WallPost t) {
        final int BEFORE = -1;
        final int EQUAL = 0;
        final int AFTER = 1;

        if (this == t) {
            return EQUAL;
        }

        if(getDate().compareTo(t.getDate()) == AFTER) {
            return BEFORE;
        } else if (getDate().compareTo(t.getDate()) == BEFORE) {
            return AFTER;
        }

        return EQUAL;
    }
}
